-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replace manage facility admin screen dropdowns with combos #6439
Conversation
acfe25c
to
64c115e
Compare
2e16c23
to
20c9677
Compare
|
||
beforeEach(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving this hook into a before each as recommended here
Spike ticket for the act pieces made here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you for doing this (combo boxes are so tricky 😭) and doing the initial research into the act warnings!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some questions/comments. Also I was not able to see the code to migrate the unarchive patient page. Is that going to be addressed in another PR or was it already migrated?.
Thanks for your work on integrating the trusswork component and sorry for the delayed review!
disabled={loading} | ||
required={true} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The required true was needed to pass a11y scan. Does the combobox handle the required in a different way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Truss doesn't give us a required
prop in their out-of-the-box component, so I added our custom required UI in the heading piece. The automated scan with non-pro Axe tools didn't surface any issues but if you see one with your tools lmk and I'm happy to try and fix it.
Worth calling out that we might want to add new component we can extend with things like the required
status since I'm guessing this won't be the last time this comes up. If folks are in agreement that this is useful happy to refactor the code a bit to make that extensible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This happens when you test this as a form. I ran through it and it looks like it's still being flagged. I think for the purpose of accessibility we might need to figure out how to add required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh actually Truss gives us an escape hatch for this. Will push a fix soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested it with axe and didn't find any problems!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
); | ||
handleClearFilter(); | ||
}); | ||
if (localState.facilityId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this condition needed? in theory the delete button will display only if a facility has been loaded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is to make Typescript happy because I changed the typing of localState.facilityId
to maybe be undefined (in the event nothing is selected) and the delete mutation hook doesn't like that. I thought having a conditional check here was preferable over casting since this delegates the type checking to the compiler rather than relying on a UI state to ensure facilityId is defined appropriately.
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for all your work on these tricky tricky combo boxes 🎃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
FRONTEND PULL REQUEST
Related Issue
Part one of #6393
Will follow up with the unarchive page in a separate PR.
Changes Proposed
ComboBox
based on the Truss version with an addedrequired
propTesting
deployed on dev5
Before
After
Screen.Recording.2023-08-31.at.10.24.27.AM.mov
Org selection enables facility selection
Screen.Recording.2023-08-31.at.10.26.26.AM.mov
Clear filters on individual combos cascade
Screen.Recording.2023-08-31.at.10.19.38.AM.mov
Clear filter button clears both boxes
Screen.Recording.2023-08-31.at.10.20.21.AM.mov
Clear org resets search results
Screen.Recording.2023-08-31.at.10.27.19.AM.mov
Additional Information
TL;DR: Are we ok sticking with fireEvent / wrapping things in
act
like we're doing currently, or do we think it's worth it to try and preferuserEvent
/ cleanact
warnings in the future? The issue is that using fireEvent / suppressing act warnings with the extra tag may result in tests that don't catch the behavior they were written for, as well as resulting in more stable tests because we're accounting for all the state updates that are happening within our component (to the extent React can tell us). On the flip side though, going back and refactoring might be expensive / unfun. I reworked some of the tests in the above fashion here in case more concrete examples are helpful.If yes, happy to make a ticket and prioritize accordingly alongside the other tech debt work we have in the pipeline. Otherwise, we can revisit if it ever comes up again.
The issue
In getting this PR in I discovered a couple of issues with the
act
warning React is throwing based on the way that we're setting up our testing suite. I'll outline what I've found here and would love opinions on options to move forward!As we've addressed in PR's like this one,
act
warnings pop up periodically in our component testing. These are often useful warnings React offers to notify us about unhandled state changes within our components that might cause unintended side effects.For this PR specifically, we need to use the
userEvent
API rather than the lower-levelfireEvent
to get tests to pass because the combo box is listening for a couple different events to happen in sequence in order to update. This caused a bunch ofact
warnings to pop up and I wanted to present a few options of handling them so we don't unnecessarily clutter our app logs and write more robust tests.Option 0 - Use fireEvent
For the reasons stated above, we can't exactly use fireEvent here because the component we're testing for relies on a bunch of bundled events working together, but we do use this method extensively in other parts of the codebase. RTL specifically recommends against this option though, so wanted to call it out as something to potentially move away from so we're testing things in a way more in line with how they recommend.
Option 1 - Wrap the userEvents in
act
One way of suppressing the warnings is to wrap the events in an
act
call. The RTL maintainer again recommends against this because the API calls already haveact
wrappers in them and the warnings might be pointing to actual state updates that need addressing. Back when Nick was on the project he also submitted a PR that called this out and installed an eslint plugin specifically for this issue. The plugin seems not to be working correctly because it's not yelling at us in instances where it should be.I've opted to temporarily go this direction to get this PR in, but will mention that this is a bandaid solution since (most) of the
act
warnings are trying to tell us that we have side effects in our component code that could result in more brittle tests.Option 2 - Update dependencies that are causing the issue in the first place and refactor our testing suite
This is, at least in my mind, the "correct" solution, but also the one that will take a bit of work. By using the higher-level interaction API and making sure we're handling all the
act
warnings, we're ensuring that we're covering any side effects that happen within our event handlers / component rendering logic. This video outlines a scenario where the act warning is trying to tell you something useful.In order for us to to take advantage of
userEvent
without act warnings though, we need to make sure that the underlying shared@testing-library/dom
dependency resolves to the same version.. I started exploring this on a separate branch but updating the packages breaks some other tests, so I punted on this for now. If we're in agreement that we want to do this, we'll need to go back and update some old tests so that everything is up to standard (and fix the eslint plugin in the meantime so that it's enforcing the new set of API's).